package com.bestcem.xm.label.grpc.service.param;

import com.alibaba.fastjson.annotation.JSONField;
import com.bestcem.xm.common.core.constant.RegTypes;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * @author ming.xue <ming.xue@idiaoyan.com>
 * @desc 自动打标签参数
 * @date 2021-05-18
 */
@Getter
@Setter
public class LabelMembersParam {
    /**
     * 企业标识
     */
    @JsonProperty("org_id")
    @JSONField(name="org_id")
    @NotNull(message = "企业标识不能为空")
    @Pattern(regexp = RegTypes.OBJECT_ID, message = "企业标识格式错误")
    private String orgId;

    /**
     * 批次号，随机字符串
     */
    @JsonProperty("batch_id")
    @JSONField(name="batch_id")
    @NotNull(message = "批次号不能为空")
    private String batchId;

    /**
     * 联系人列表
     */
    @Valid
    @NotEmpty(message = "联系人列表不能为空")
    private List<MemberParam> members;

    /**
     * 清理内存
     */
    public void clean() {
        if (!CollectionUtils.isEmpty(members)) {
            members.clear();
            members = null;
        }
    }
}
